/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class TheSumOfLuckyNumbers {
public:
    vector <int> sum(int n);
};
const int maxn = (int)1e6;
vector< int > lnum; // lucky numbers;
int sz;

int dp[maxn+5];
int path[maxn+5];

inline void generateLucky(int n) {
    lnum.clear();
    queue<int> q;

    q.push(4);
    q.push(7);
    while ( q.empty()==false ) {
        int f = q.front();
        q.pop();
        lnum.pb(f);

        int v1 = (f*10)+4;
        int v2 = (f*10)+7;
        if ( v1 <= n ) {
            q.push(v1);
        }
        if ( v2 <= n ) {
            q.push(v2);
        }
    }
    sz = SZ(lnum);
}

inline void INI(int n) {
    dp[0]=0;
    
    for (int i=1;i<=n;++i) {
        dp[i]=maxn;
        for (int j=0;j<sz;++j) {
            if ( lnum[j] > i )break;
            int v1 = 1+ dp[i-lnum[j]];
            if( v1 < dp[i] ){
              dp[i]=v1;
              path[i] = lnum[j];
            }
        }
    }
}

vector <int> TheSumOfLuckyNumbers :: sum(int n) {

    generateLucky(n);
    INI(n);
    
    if( dp[n]>=maxn){
      return vector<int>();
    }
    vector<int> pp;
    while( n > 0 ){
      int newn = n-path[ n ] ;
      pp.pb( path[n] );
      n = newn;
    }
    return pp;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, int p0, bool hasAnswer, vector <int> p1) {
    cout << "Test " << testNum << ": [" << p0;
    cout << "]" << endl;
    TheSumOfLuckyNumbers *obj;
    vector <int> answer;
    obj = new TheSumOfLuckyNumbers();
    clock_t startTime = clock();
    answer = obj->sum(p0);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << "{";
        for (int i = 0; int(p1.size()) > i; ++i) {
            if (i > 0) {
                cout << ",";
            }
            cout << p1[i];
        }
        cout << "}" << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << "{";
    for (int i = 0; int(answer.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << answer[i];
    }
    cout << "}" << endl;
    if (hasAnswer) {
        if (answer.size() != p1.size()) {
            res = false;
        } else {
            for (int i = 0; int(answer.size()) > i; ++i) {
                if (answer[i] != p1[i]) {
                    res = false;
                }
            }
        }
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    int p0;
    vector <int> p1;

    {
        // ----- test 0 -----
        p0 = 1000000;
        int t1[] = {4, 4, 44444, 477774, 477774};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        p0 = 12;
        int t1[] = {4,4,4};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        p0 = 13;
        p1.clear() /*{}*/;
        all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        p0 = 100;
        int t1[] = {4,4,4,44,44};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
